const fs = require('fs')
const path = require('path')
const ReadStream = require('./source/ReadStream')

const rs = new ReadStream(path.resolve(__dirname,'01.test.js'), {
    flags: 'r',
    encoding: null,// 默认编码是buffer
    autoClose: false,// 调用close
    // emitClose: true,// 触发一个clos事件
    start: 0,
    // end: 4,
    highWaterMark: 3 // 每次读取的数据个数
});

rs.on('open', function (fd) {
    console.log('open', fd)
})

rs.on('data', function (chunk) {
    console.log(chunk)
    rs.pause();
})

rs.on('end', function () {
    console.log('end')
})
rs.on('close', function () {
    console.log('close')
})
rs.on('error', function (err) {
    console.log('err', err);
})

// setInterval(() => {
//     rs.resume()
// }, 1000);